//package com.huiztech.kaoqinji;
//
//import java.util.ArrayList;
//import java.util.List;
//import android.content.Context;
//import android.content.Intent;
//import android.graphics.Bitmap;
//import android.os.Bundle;
//import android.text.Editable;
//import android.text.TextWatcher;
//import android.view.LayoutInflater;
//import android.view.View;
//import android.view.ViewGroup;
//import android.view.View.OnClickListener;
//import android.widget.AdapterView;
//import android.widget.AdapterView.OnItemClickListener;
//import android.widget.ArrayAdapter;
//import android.widget.BaseAdapter;
//import android.widget.EditText;
//import android.widget.Filter;
//import android.widget.Filterable;
//import android.widget.ImageView;
//import android.widget.LinearLayout;
//import android.widget.ListView;
//import android.widget.TextView;
//import com.huiztech.common.http.HuizBaseJsonResponseHandler.Callback;
//import com.huiztech.kaoqinji.model.ClientData;
//import com.huiztech.kaoqinji.model.ClientDetail;
//import com.huiztech.kaoqinji.mvc.KaoqinBaseActivity;
//import com.nostra13.universalimageloader.core.DisplayImageOptions;
//import com.nostra13.universalimageloader.core.ImageLoader;
//import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
//import com.nostra13.universalimageloader.core.assist.ImageScaleType;
//
//public class Visit1Activity extends KaoqinBaseActivity implements OnClickListener {
//
//    private ListView listView;
//    private EditText searchEdit;
//    private List<ClientDetail> list;
//    private List<String> arrayList;
//    private LinearLayout backLayout;
//    private LinearLayout addLayout;
//    private VisitAdapter adapter;
//    private ArrayAdapter<String> arrayAdapter;
//    private String[] searchStr;
//
//    @Override
//    protected void onCreate(Bundle savedInstanceState) {
//        super.onCreate(savedInstanceState);
//        setContentView(R.layout.activity_visit);
//
//        findView();
//
//        searchEdit.addTextChangedListener(new watcher());
//        backLayout.setOnClickListener(this);
//        addLayout.setOnClickListener(this);
//        listView.setOnItemClickListener(new OnItemClickListener() {
//
//            @Override
//            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
//                Intent intent = new Intent(Visit1Activity.this, ClientDetailActivity.class);
//                intent.putExtra("customerPosition", position);
//                startActivity(intent);
//            }
//        });
//    }
//
//    @Override
//    public void onClick(View v) {
//        switch (v.getId()) {
//        case R.id.visit_back_layout:
//            finish();
//            break;
//        case R.id.visit_add_layout:
//            startActivity(new Intent(Visit1Activity.this, AddClientActivity.class));
//            break;
//        default:
//            break;
//        }
//    }
//
//    private void findView() {
//        listView = (ListView) findViewById(R.id.list);
//        searchEdit = (EditText) findViewById(R.id.visit_search_edit);
//        backLayout = (LinearLayout) findViewById(R.id.visit_back_layout);
//        addLayout = (LinearLayout) findViewById(R.id.visit_add_layout);
//    }
//
//    @Override
//    protected void onResume() {
//        super.onResume();
//        list = new ArrayList<ClientDetail>();
//        arrayList = new ArrayList<String>();
//        arrayAdapter = new ArrayAdapter<String>(Visit1Activity.this, R.layout.search_item, arrayList);
//        controller.getCustomerData(new Callback<ClientData>() {
//
//            @Override
//            public void execute(ClientData obj) {
//                list.clear();
//                list = obj.getData();
//                adapter = new VisitAdapter(Visit1Activity.this, list);
//                listView.setAdapter(adapter);
//            }
//        });
//    }
//
//    /**
//     * EditText 监听输入框
//     *
//     * @author yuanlong
//     *
//     */
//
//    class watcher implements TextWatcher {
//
//        @Override
//        public void afterTextChanged(Editable s) {
//
//        }
//
//        @Override
//        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
//
//        }
//
//        @Override
//        public void onTextChanged(CharSequence s, int start, int before, int count) {
//            adapter.getFilter().filter(s);
//        }
//    }
//
//    /**
//     * 客户列表适配器
//     *
//     * @author yuanlong
//     *
//     */
//    public class VisitAdapter extends BaseAdapter implements Filterable {
//
//        private List<ClientDetail> clientDetailList;
//        Context context;
//        private LayoutInflater inflater;
//        protected ImageLoader imageLoader = ImageLoader.getInstance();
//        DisplayImageOptions options;
//        private ClientDetailFilter filter;
//
//        public final class ViewHolder {
//            ImageView imageView;
//            TextView nameText;
//            TextView companyText;
//        }
//
//        public VisitAdapter(Context context, List<ClientDetail> clientDetailList) {
//            this.clientDetailList = clientDetailList;
//            this.context = context;
//            inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
//            imageLoader.init(ImageLoaderConfiguration.createDefault(context));
//            options = new DisplayImageOptions.Builder().showStubImage(R.drawable.moren)
//                    .showImageForEmptyUri(R.drawable.moren).showImageOnFail(R.drawable.moren).cacheInMemory()
//                    .cacheOnDisc().imageScaleType(ImageScaleType.IN_SAMPLE_POWER_OF_2)
//                    .bitmapConfig(Bitmap.Config.RGB_565).build();
//        }
//
//        @Override
//        public int getCount() {
//            return clientDetailList.size();
//        }
//
//        @Override
//        public Object getItem(int position) {
//            return clientDetailList.get(position);
//        }
//
//        @Override
//        public long getItemId(int position) {
//            return position;
//        }
//
//        @Override
//        public View getView(int position, View convertView, ViewGroup parent) {
//            ClientDetail c = clientDetailList.get(position);
//            final ViewHolder holder;
//            if (convertView == null) {
//                holder = new ViewHolder();
//                convertView = inflater.inflate(R.layout.visit_list_item, null);
//                holder.nameText = (TextView) convertView.findViewById(R.id.visit_item_name);
//                holder.companyText = (TextView) convertView.findViewById(R.id.visit_item_company);
//                holder.imageView = (ImageView) convertView.findViewById(R.id.visit_item_image);
//                convertView.setTag(holder);
//            } else {
//                holder = (ViewHolder) convertView.getTag();
//            }
//            if (c.getName() != null) {
//                holder.nameText.setText(c.getName());
//            }
//            if (c.getCompanyName() != null) {
//                holder.companyText.setText(c.getCompanyName());
//            }
//            if(c.getImage().equals("")){
//                holder.imageView.setBackgroundResource(R.drawable.moren);
//            }else{
//                imageLoader.displayImage(AppConst.KAOQIN_UPLOAD_URL + c.getImage(), holder.imageView, options);
//            }
//            return convertView;
//        }
//
//        @Override
//        public Filter getFilter() {
//            if (filter == null) {
//                filter = new ClientDetailFilter(clientDetailList);
//            }
//            return filter;
//        }
//
//        private class ClientDetailFilter extends Filter {
//
//            private List<ClientDetail> original;
//
//            public ClientDetailFilter(List<ClientDetail> clientDetail) {
//                this.original = clientDetail;
//            }
//
//            @Override
//            protected FilterResults performFiltering(CharSequence constraint) {
//                FilterResults results = new FilterResults();
//                if (constraint == null || constraint.length() == 0) {
//                    results.values = original;
//                    results.count = original.size();
//                } else {
//                    List<ClientDetail> mList = new ArrayList<ClientDetail>();
//                    for (ClientDetail c : original) {
//                        if (c.getName().toUpperCase().startsWith(constraint.toString().toUpperCase())) {
//                            mList.add(c);
//                        }
//                    }
//                    results.values = mList;
//                    results.count = mList.size();
//                }
//                return results;
//            }
//
//            @SuppressWarnings("unchecked")
//            @Override
//            protected void publishResults(CharSequence constraint, FilterResults results) {
//                clientDetailList = (List<ClientDetail>) results.values;
//                model.put("clientDetail", clientDetailList);
//                notifyDataSetChanged();
//            }
//
//        }
//
//    }
//}
